/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @private
 *
 * @properties={typeid:24,uuid:"3BCC668B-B9BE-4D24-B5A6-EF26D86A3C0B"}
 */
function ir_empresa(event) {
	
	/** @type {JSFoundSet<db:/pigeon_board/adm_t900_empresas>} */
	var fs_adm_t900_empresas = databaseManager.getFoundSet(scopes.adm_t900_empresas.$DATA_SOURCE);
	fs_adm_t900_empresas.loadRecords(foundset.getSelectedRecord().adm_t900_usuarios_to_adm_t900_empresas.adm_t900_empresas_id);
	globals.ir_formulario(forms.frm_adm_t900_empresas.controller.getName(), fs_adm_t900_empresas, globals.$MODO_LECTURA);
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @private
 *
 * @properties={typeid:24,uuid:"03214469-A229-4F46-8CF0-C1F8DBADB4F3"}
 */
function ir_perfil(event) {
	
	/** @type {JSFoundSet<db:/pigeon_board/adm_t900_perfiles>} */
	var fs_adm_t900_perfiles = databaseManager.getFoundSet(scopes.adm_t900_perfiles.$DATA_SOURCE);
	globals.ir_formulario(forms.frm_adm_t900_perfiles.controller.getName(), fs_adm_t900_perfiles, globals.$MODO_LECTURA);
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @private
 *
 * @properties={typeid:24,uuid:"18D01289-7EDC-43DB-9626-E60329E7920E"}
 */
function borrar_empresa(event) {

	adm_t900_empresas_id = null;
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"6972442F-C365-4BD5-8043-8A6EA456747E"}
 */
function borrar_perfil(event) {

	adm_t900_perfiles_id = null;
}

/**
 * @properties={typeid:24,uuid:"BC60A8ED-A0D1-4242-BD39-F349B6F3AEA8"}
 */
function doEdit(){
	
	elements.btn_ir_empresa.visible = false;
	elements.btn_ir_perfil.visible = false;
	elements.btn_borrar_empresa.visible = false;
	elements.btn_borrar_perfil.visible =false;
	
	if (foundset.getSelectedRecord().isNew()){
		if (adm_t900_empresas_id  != null){
			globals.hide_btn_reset_fields_elment(controller.getName(),elements.vlst_adm_t900_empresas_id.getName());
			controller.focusField(elements.vlst_adm_t900_perfiles_id.getName(),true);
		}
	}
}

/**
 * @properties={typeid:24,uuid:"1027F3A0-3343-4C8F-9D87-DDD21E37CE1B"}
 */
function hide_btn_reset_fields(){
	
	elements.btn_ir_empresa.visible = true;
	elements.btn_ir_perfil.visible = true;
	elements.btn_borrar_empresa.visible = true;
	elements.btn_borrar_perfil.visible =true;
}

/**
 * Handle changed data.
 *
 * @param {String} oldValue old value
 * @param {String} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @private
 *
 * @properties={typeid:24,uuid:"A6FF3FFB-FE7B-4077-8F1E-C22A9EF47687"}
 */
function onDataChange_b_es_super_administrador(oldValue, newValue, event) {

	if (newValue == 1){
		adm_t900_empresas_id = null;
		adm_t900_perfiles_id = null;
		b_es_adm = 0;
		elements.vlst_adm_t900_empresas_id.enabled = false;
		elements.vlst_adm_t900_perfiles_id.enabled = false;
		elements.chk_b_es_adm.enabled = false;
	}else{
		elements.vlst_adm_t900_empresas_id.enabled = true;
		elements.vlst_adm_t900_perfiles_id.enabled = true;
		elements.chk_b_es_adm.enabled = true;
	}
	return true
}

/**
 * @param {JSEvent} event
 *
 * @properties={typeid:24,uuid:"F169E22E-33D4-469F-8059-65C6DA896EF0"}
 */
function opciones(event){
	
	var submenu_cambiar_contraseña = $menu.addMenuItem("Cambiar contraseña", cambiar_contraseña);
	submenu_cambiar_contraseña.methodArguments = [event];
	
	var submenu_restablecer_contraseña = $menu.addMenuItem("Restablecer contraseña", restablecer_contraseña);
}

/**
 * Formulario cambio contraseña
 * @author Roberto J. Blasco
 * @version 1.0
 * @properties={typeid:24,uuid:"2A40FE85-5CC5-4A29-81A4-CB984374EF9D"}
 */
function cambiar_contraseña(){
	
	forms.frm_adm_t900_usuarios_cambio_contraseña.$pwd_original = foundset.getSelectedRecord().s_md5_pwd;
	forms.frm_adm_t900_usuarios_cambio_contraseña.$pwd1 = "";
	forms.frm_adm_t900_usuarios_cambio_contraseña.$pwd2 = "";
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms.frm_adm_t900_usuarios_cambio_contraseña.foundset.loadRecords(foundset.getSelectedRecord().adm_t900_usuarios_id);
	forms.frm_adm_t900_usuarios_cambio_contraseña._doEdit();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.frm_adm_t900_usuarios_cambio_contraseña);
}

/**
 * @properties={typeid:24,uuid:"2E4E5EC8-652C-4033-9C3E-46B4227F3D2C"}
 */
function restablecer_contraseña(){
	
	foundset.getSelectedRecord().s_md5_pwd = utils.stringMD5HashBase64("1234");
}
